package br.fumec.main;

import java.util.ArrayList;
import java.util.Random;
import java.util.TreeSet;


public class Tabuleiro {
	int[] queen;
	int[] dn;
	int[] dp;
	
	public Tabuleiro(int qtdRainhas){
		queen = new int[qtdRainhas];
		dn = new int[2*qtdRainhas-1];
		dp = new int[2*qtdRainhas-1];
		
		for(int i = 0; i < queen.length; i++){
			queen[i] = i;
		}
		
		for(int i = 0; i < dn.length; i++){
			dn[i] = 0;
		}
		dn[dn.length/2] = qtdRainhas;
		
		for(int i = 0; i < dp.length; i++){
			if((i & 1) == 0){
				dp[i] = 1;
			}else{
				dp[i] = 0;
			}
		}
	}
	
	public int computeCollisions(){
		int qtde = 0;
		for(int i = 0; i < dp.length; i++){
			if(dp[i] > 1){
				qtde += dp[i]-1;
			}
		}
		for(int i = 0; i < dn.length; i++){
			if(dn[i] > 1){
				qtde += dn[i]-1;
			}
		}
		return qtde;
	}
	
	public int computeCollisions(int q1, int q2){
		TreeSet<Integer> dps = new TreeSet<>();
		dps.add(queen[q1]+queen[q1]);
		dps.add(queen[q2]+queen[q2]);
		dps.add(queen[q1]+q1);
		dps.add(queen[q2]+q1);

		TreeSet<Integer> dns = new TreeSet<>();
		dps.add(queen[q1]+queen[q1]);
		dps.add(queen[q2]+queen[q2]);
		dps.add(queen[q2]+q2);
		dps.add(queen[q1]+q2);
		
		return 1;
	}
	
//	{
//		colisouesAnterior = chamar computeCollis para as duass rainhas
//		
//	}
	
	public void shuffle(){
		Random rnd = new Random();
		for(int i = 0; i < queen.length; i++){
			//swap(i, rnd.nextInt(queen.length));
		}
	}
	
	public ArrayList<Integer> computeAttacks(){
		ArrayList<Integer> rainhas = new ArrayList<>();
		for(int i = 0; i < queen.length; i++){
			int p = i+queen[i];
			int n = (queen[i]-i) + (queen.length-1);
			
			if(dp[p] > 1 || dn[n] > 1){
				rainhas.add(queen[i]);
			}
		}
		return rainhas;
	}
}